package com.chen.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.springboot.domain.Player;
import com.chen.springboot.domain.Team;

import com.chen.springboot.mapper.PlayerMapper;
import com.chen.springboot.mapper.mongoMapper.PlayersMapper;
import com.chen.springboot.service.PlayerService;
import com.chen.springboot.vo.Players;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author chenchao
 * @date 2022/6/22 14:49
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PlayerServiceImpl extends ServiceImpl<PlayerMapper, Player> implements PlayerService {

    @Resource
    private PlayerMapper playerMapper;



    public IPage<Player> selectPage(Integer pageNum, Integer pageSize,
                                  String displayName,
                                  String country,
                                  String position,
                                  String displayAbbr) {
//        创建Page1对象
        IPage<Player> page = new Page<Player>(pageSize, pageNum);
//QueryWrapper如果name不为空进行模糊查询
        QueryWrapper queryWrapper = new QueryWrapper();

        if(!"".equals(displayName)){
            queryWrapper.like("displayName",displayName);
        }

        if(!"".equals(country)){
            queryWrapper.like("country",country);
        }
        if(!"".equals(position)){
            queryWrapper.like("position",position);
        }
        if(!"".equals(displayAbbr)){
            queryWrapper.like("displayAbbr",displayAbbr);
        }
        Page<Player> selectPage = playerMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper);
        return selectPage;

    }


}
